#pragma once

#include <butil/logging.h>
#include <brpc/server.h>
#include <frpc.pb.h>

class PureTask
{
public:
    brpc::Controller *cntl;
    google::protobuf::Closure *done;
    virtual ~PureTask() {}
    virtual void run() = 0;

    void run_and_delete()
    {
        run();
        delete this;
    }
};
class ReadBarTask : public PureTask
{
public:
    virtual ~ReadBarTask() {}
    const frpcType::GetBarRequest *request;
    frpcType::DefaultArg *response;
    virtual void run() override;
};
class ReadBarRangeTask : public PureTask
{
public:
    virtual ~ReadBarRangeTask() {}
    const frpcType::GetBarRequest *request;
    frpcType::DefaultArg *response;
    virtual void run() override;
};
struct UpdateBarTask : public PureTask
{

public:
    virtual ~UpdateBarTask() {}
    const frpcType::UpdateBarRequest *request;
    frpcType::DefaultArg *response;
    virtual void run() override;
};

static void *process_thread(void *args)
{
    PureTask *job = static_cast<PureTask *>(args);
    job->run_and_delete();
    return NULL;
}